 #ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTreeWidget>
#include <QLabel>
#include <QString>
#include <QTableView>
#include "pm.h"
#include "dmdlg.h"
#include "building.h"
#include "floor.h"
#include "room.h"
#include "device.h"
#include "settabwidgetpage.h"
#include "maingroup.h"
#include "middlegroup.h"
#include "groupaddress.h"
#include "errortodo.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
public slots:
    void relationGA();
    
    void searchDevice();

    void updateSerialStatus(int res);
private slots:
    void timeUpdate();
    
    void updateBuildingTreeWidgetMenu(const QPoint&);
    
    void updateGATreeWidgetMenu(const QPoint&);
    
    void setTabWidget(QTreeWidgetItem *curItem, int column);
    
    void openProject();
    
    void closeProject();
    
    void createProject();
    
    void DM();
    
    void addBuilding();
    
    void addFloor();
    
    void addRoom();
    
    void addDevice();
    
    void addCommunicationObject(QTreeWidgetItem *deviceItem);
    
    void addMainGroup();
    
    void addMiddleGroup();
    
    void addGA();
    
    void downloadPA();
    
    void downloadData();
    
    void selectAboutMenu(bool checked);
    
    void selectCloseProMenu(bool checked);
    
    void selectCreateProMenu(bool checked);
    
    void selectDBMaintainMenu(bool checked);
    
    void selectExitMenu(bool checked);
    
    void selectHelpManualMenu(bool checked);
    
    void selectDMMenu(bool checked);
    
    void selectOnlineCheckMenu(bool checked);
    
    void selectOpenProMenu(bool checked);
    
    void selectPlugInMenu(bool checked);
    
    void selectactionProductSummaryMenu(bool checked);
    
    void selectSerialPortMenu(bool checked);
    
    void selectStackMenu(bool checked);
    
    void selectTecnicalSupportMenu(bool checked);
    
    void selectTileMenu(bool checked);
    
    void productSummary();
    
    void deviceCheck();
    
    void plugIn();
    
    void DBMaintenance();
    
    void OnLineCheck();
    
    void SerialPort();
    
    void showBuildingSubWindow();
    
    void showGASubWindow();
    
    void helpManual();
    
    void technicalSupport();
    
    void about();

    void buildingTreeWidgetDelFunc();

    void GATreeWidgetDelFunc();
    
    void updateGroupObjectViewMenu(const QPoint &);

    void buildingAttributeSet();

    void floorAttributeSet();
    
    void roomAttributeSet();
    
    void deviceAttributeSet();
    
    void mainGroupAttributeSet();
    
    void middleGroupAttributeSet();
    
    void groupAddressAttributeSet();
    
    void cancelLinkGA();
    
private:
    Ui::MainWindow *ui;
    
    QTreeWidgetItem *buildingTreeWidgetRoot;  //建筑树状窗口根节点
    QTreeWidgetItem *GATreeWidgetRoot;  //群组地址树状窗口根节点
    
    Project *localProject;  //当前项目对象指针
    Building *localBuilding;  //当前建筑对象指针
    Floor *localFloor;  //当前楼层
    Room *localRoom;  //当前房间
    Device *localDevice;  //当前设备
    MainGroup *localMainGroup;  //当前主群组
    MiddleGroup *localMiddleGroup;  //当前中间组
    GroupAddress *localGroupAddress;  //当前组地址
    QString localDeviceType;  //当前选择的设备的类型
    
    SetTabWidgetPage *setTabWidgetFun;  //tabWidget的设置方法指针
    
    QLabel *proNameLabel;  //状态栏显示项目名
    QLabel *serialPortStatusLabel;  //状态栏显示串行端口连接状态
    QLabel *currentTimeLabel;  //状态栏显示当前时间
    
    QAction *buildingTreeWidgetCopyAction;  //建筑TreeWidget拷贝动作
    QAction *buildingTreeWidgetPasteAction;  //~黏贴~
    QAction *buildingTreeWidgetCutAction;  //~剪贴~
    QAction *buildingTreeWidgetDelAction;  //~删除~
    QAction *buildingAttributeSetAction;  //~建筑属性~
    QAction *floorAttributeSetAction;  //~楼层属性~
    QAction *roomAttributeSetAction;  //~房间属性~
    QAction *deviceAttributeSetAction;  //~设备属性~
    QAction *mainGroupAttributeSetAction;  //~主组属性~
    QAction *middleGroupAttributeSetAction;  //~中间组属性~
    QAction *GAAttributeSetAction;  //~子组属性~
    QAction *GATreeWidgetCopyAction;  //群组TreeWidget拷贝动作
    QAction *GATreeWidgetPasteAction;  //~黏贴~
    QAction *GATreeWidgetCutAction;  //~剪贴~
    QAction *GATreeWidgetDelAction;  //~删除~
    
    QWidget *buildingPage;  //建筑widget窗口指针
    QWidget *floorPage;  //楼层~
    QWidget *roomPage;  //房间~
    QWidget *devicePage;  //设备
    QWidget *parameterPage;  //参数~
    QWidget *funcPage;  //功能~
    QWidget *groupObjectPage;  //组对象~
    QWidget *objectRelationPage;  //对象关联~
    QWidget *mainGroupPage;  //主群组~
    QWidget *middleGroupPage;  //中间组~
    QWidget *GAPage;  //群组地址~
    QWidget *GARelationPage;  //群组地址关联~
    
    QGridLayout *buildingLayout;  //建筑窗口格栅布局指针
    QGridLayout *floorLayout;  //楼层~
    QGridLayout *roomLayout;  //房间~
    QGridLayout *deviceLayout;  //设备~
    QGridLayout *parameterLayout;  //参数~
    QGridLayout *funcLayout;  //功能~
    QGridLayout *groupObjectLayout;  //组对象
    QGridLayout *objectRelationLayout;  //对象关联~
    QGridLayout *mainGroupLayout;  //主群组~
    QGridLayout *middleGroupLayout;  //中间组~
    QGridLayout *GALayout;  //群组地址~
    QGridLayout *GARelationLayout;  //群组地址关联~
    
    QSqlRelationalTableModel *buildingModel;  //建筑数据库处理模型
    QSqlRelationalTableModel *floorModel;  //楼层~
    QSqlRelationalTableModel *roomModel;  //房间~
    QSqlRelationalTableModel *deviceModel;  //设备~
    QSqlRelationalTableModel *funcModel;  //功能~
    QSqlRelationalTableModel *groupObjectModel;  //组对象~
    QSqlRelationalTableModel *objectRelationModel;  //对象关联~
    QSqlRelationalTableModel *mainGroupModel;  //主群组~
    QSqlRelationalTableModel *middleGroupModel;  //中间组~
    QSqlRelationalTableModel *GAModel;  //群组地址~
    QSqlRelationalTableModel *GARelationModel;  //群组地址关联~
    
    QTableView *buildingView;  //建筑tableView
    QTableView *floorView;  //楼层~
    QTableView *roomView;  //房间~
    QTableView *deviceView;  //设备~
    QTableView *funcView;  //功能~
    QTableView *groupObjectView;  //组对象~
    QTableView *objectRelationView;  //对象关联~
    QTableView *mainGroupView;  //主群组~
    QTableView *middleGroupView;  //中间组~
    QTableView *GAView;  //群组地址~
    QTableView *GARelationView;  //群组地址关联~
    
    typedef enum ModelAndViewType {  //数据库模型和显示结构类型
        BUILDING = 1,
        FLOOR,
        ROOM,
        DEVICE,
        FUNC,
        GROUPOBECT,
        OBJECTRELATION,
        MAINGROUP = 11,
        MIDDLEGROUP,
        GA,
        GARELATION
    }ModelAndViewType;
    
    typedef enum itemTypeNum {  //treeWidget的节点编号
        NODEBUILDINGROOT,
        NODEBUILDING,
        NODEFLOOR,
        NODEROOM,
        NODEDEVICE,
        NODECHANNEL,
        NODEGROUPROOT = 10,
        NODEMAINGROUP,
        NODEMIDDLEGROUP,
        NODEGA,
        NODEDEVICESENDGA = 20
    }ItemTypeNum;
    
    void initStatusBar();

    void initMainWindow();
    
    void initTreeWidget();
    
    void createAllCusTomMadeWidget();
    
    void createAllModel();
    
    void createAllTableView();
    
    void createAllGridLayout();
    
    void setAllWidgetPage();

    void updateModelAndTableView(ModelAndViewType type, QString filter);
    
    void initTabWidget();
    
    void setTitle();
    
    QStringList selectDeviceDB();
    
    void removeTabWidgetPage(int itemType);
    
    void setInitWidget();
    
    void setBuildingRootWidget();
    
    void setBuildingWidget();
    
    void setFloorWidget();
    
    void setRoomWidget();
    
    void setDeviceWidget(QString deviceType);
    
    void setChannelWidget();
    
    void setGARootWidget();
    
    void setMainGroupWidget();
    
    void setMiddleGroupWidget();
    
    void setGAWidget();

    void loadToTreeWidgetFromBuildingDB(int id, QTreeWidgetItem *item);

    void loadToTreeWidgetFromGADB(int id, QTreeWidgetItem *item);

    void loadDataFromDBToTreeWidget();

    void del(QTreeWidgetItem *node);

    void setAction();

    QString getAddressFromItemName(QString itemName, ItemTypeNum type);
    
    void deleteDataFromDBByName(QTreeWidgetItem *item);
    
    ErrorToDo *error;
};

#endif // MAINWINDOW_H
